<template>
	<view class="container" style="padding-top: 10px;">
		<view class="floor">
			<view class="title">回访意见</view>
			<view class="content">
				<textarea placeholder="请输入回访意见" v-model="returnRemark"></textarea>
			</view>
		</view>
		<view class="floor">
			<view class="title">回访结果</view>
			<view class="content">
				<textarea placeholder="请输入回访结果" v-model="returnResult"></textarea>
			</view>
		</view>
		<view class="floor">
			<view class="title">图片(长按可删除)</view>
			<view class="content" style="height: 30vh;overflow: overlay;">
				<image :src="item" v-for="(item,index) in picList" @longtap="deleteIt(item,index)"></image>
				<button @click="addPic">+</button>
			</view>
		</view>
		<button type="primary" style="width: 80%;margin: 20px auto;" @click="sendInfo();">提交</button>
	</view>
</template>

<script>
	import config from '@/config/config.js'
	import {
		flowComplaintsIinsert,
		fileUpload
	} from "@/api/home.js"
	export default {
		data() {
			return {
				picList: []
			}
		},
		methods: {
			addPic() {
				var that = this;
				uni.chooseImage({
					success(res) {
						console.log('res', res);
						var arr = res.tempFilePaths;
						for (var i = 0; i < arr.length; i++) {
							uni.uploadFile({
								url: 'https://www.ansteelproperty.com/special/dictionary/files/upload/',
								header: {
									"Authorization": uni.getStorageSync("token"),
									"X-Requested-With": 'XMLHttpRequest',
									"Accept": "application/json"
								},
								method: "post",
								filePath: arr[i],
								fileType: 'image',
								name: 'file',
								formData: {
									'filea': arr[i]
								},
								success: (result) => {
									var json = JSON.parse(result.data);
									if (json.code == 200) {
										const redirectUri = `${config.baseUrl}`
										console.log('redirectUri', redirectUri)
										that.picList.push(redirectUri + json.msg)
									}
								}
							});
						}
					}
				})
			},
			deleteIt(item, index) {
				var that = this;
				uni.showModal({
					title: "提示",
					content: "是否确认删除",
					success(res) {
						if (res.confirm == true) {
							that.picList.splice(index, 1)
						}
					}
				})
			},
			sendInfo() {
				this.dict.applyCategory = this.array[this.index]
				this.dict.state = "已回访";
				this.dict.client = "小程序";
				this.dict.returnImg = this.picList.join(",");
				insertConfigFlowRepairBlock({
					...this.dict
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: "操作成功",
							icon: "none",
							duration:1000,
							success() {
								uni.navigateBack({
									delta:1
								})
							}
						})
					} else {
						uni.showToast({
							title: "操作失败",
							icon: "none"
						})
					}
				}).catch(err => {
					uni.showToast({
						title: "网络异常",
						icon: "none"
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	uni-input {
		height: 70rpx !important;
		line-height: 70rpx !important;
	}

	.floor {
		width: 100%;
		overflow: hidden;
		margin-bottom: 5px;

		.title {
			float: left;
			width: 120px;
			line-height: 36px;
			text-align: center;
			font-size: 14px;
			color: #666666;
			background-color: #fff;
		}

		.content {
			float: left;
			width: calc(100% - 130px);
			height: 70rpx;
			line-height: 70rpx;
			border-bottom: 1px solid #ccc;

			uni-button {
				width: 50px;
				height: 50px;
				display: block;
				float: left;
				margin: 10px;
			}

			uni-image {
				width: 50px;
				height: 50px;
				display: block;
				float: left;
				margin: 10px;
			}
		}
	}
</style>